message("项目名称:${PROJECT_NAME}")
message("项目源码目录:${PROJECT_SOURCE_DIR}")

#创建构建后的输出目录
if(NOT EXISTS "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin")
    message("创建目录:${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin")
    file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin")
endif()
if(NOT EXISTS "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib")
    message("创建目录:${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib")
    file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib")
endif()

# 归档静态库到指定目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib")
# 归档动态库到指定目录
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin")
# 归档可执行文件到指定目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin")

#如果需要exe文件能单独运行,需要拷贝mingw的一些dll
file(GLOB MINGW_DLL "$ENV{MINGW_HOME}/bin/*.dll")
file(COPY ${MINGW_DLL} DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
message("拷贝mingw相关库:${WXWIDGETS_MINGW_DLL},到目录${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")

#拷贝icons目录文件
#创建icons目录
set(ICON_DIR "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin/icons")
if(NOT EXISTS ${ICON_DIR})
    message("创建目录:${ICON_DIR}")
    file(MAKE_DIRECTORY ${ICON_DIR})
endif()
file(GLOB ICONS "${PROJECT_SOURCE_DIR}/icons/*")
file(COPY ${ICONS} DESTINATION DESTINATION ${ICON_DIR})

#开始wxWidgets相关设置
#添加wxWidgets的include文件目录
message("wxWidgets的根目录:${WXWIDGETS_PATH}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    include_directories("${WXWIDGETS_PATH}/lib/gcc_dll/mswud")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    include_directories("${WXWIDGETS_PATH}/lib/gcc_dll/mswu")
else()
    include_directories("${WXWIDGETS_PATH}/lib/gcc_dll/mswu")
endif()
include_directories("${WXWIDGETS_PATH}/include")

#添加wxWidgets,opencv的库搜索路径
set(WXWIDGETS_DLL_PATH "${WXWIDGETS_PATH}/lib/gcc_dll")
#添加opencv的库搜索路径
set(OPENCV_DLL_PATH "${OPENCV_PATH}/x64/mingw/bin")
link_directories(${WXWIDGETS_DLL_PATH} ${OPENCV_DLL_PATH})

add_executable(wxWidgetsCAD ${SOURCES_DIR} ${RES_DIR})

message("wxWidgets的库搜索路径:${WXWIDGETS_PATH}/lib/gcc_dll")
set(WXWIDGETS_DEBUG_DLL_NAMES wxmsw30ud_core_gcc_custom wxbase30ud_gcc_custom wxmsw30ud_aui_gcc_custom)
set(WXWIDGETS_RELEASE_DLL_NAMES wxmsw30u_core_gcc_custom wxbase30u_gcc_custom wxmsw30u_aui_gcc_custom)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    foreach(dllName ${WXWIDGETS_DEBUG_DLL_NAMES})
        target_link_libraries(wxWidgetsCAD "-l${dllName}")
        message("链接到wxWidgets的相关库:${dllName}")
    endforeach(dllName)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    foreach(dllName ${WXWIDGETS_RELEASE_DLL_NAMES})
        target_link_libraries(wxWidgetsCAD "-l${dllName}")
        message("链接到wxWidgets的相关库:${dllName}")
    endforeach(dllName)
else()
    foreach(dllName ${WXWIDGETS_RELEASE_DLL_NAMES})
        target_link_libraries(wxWidgetsCAD "-l${dllName}")
        message("链接到wxWidgets的相关库:${dllName}")
    endforeach(dllName)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    foreach(dllName ${WXWIDGETS_DEBUG_DLL_NAMES})
        file(COPY "${WXWIDGETS_DLL_PATH}/${dllName}.dll" DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
        message("拷贝wxwidgets相关库:${dllName},到目录${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    endforeach(dllName)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    foreach(dllName ${WXWIDGETS_RELEASE_DLL_NAMES})
        file(COPY "${WXWIDGETS_DLL_PATH}/${dllName}.dll" DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
        message("拷贝wxwidgets相关库:${dllName},到目录${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    endforeach(dllName)
else()
    foreach(dllName ${WXWIDGETS_RELEASE_DLL_NAMES})
        file(COPY "${WXWIDGETS_DLL_PATH}/${dllName}.dll" DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
        message("拷贝wxwidgets相关库:${dllName},到目录${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
    endforeach(dllName)
endif()
#结束wxWidgets相关设置

# #opencv配置开始
# set(OPENCV_VERSION "452")
# #添加opencv的include文件目录
# message("opencv的根目录:${OPENCV_PATH}")
# include_directories("${OPENCV_PATH}/include")

# message("opencv的库搜索路径:${OPENCV_DLL_PATH}")
# set(OPENCV_DEBUG_DLL_NAMES "-llibopencv_core452d -llibopencv_highgui452d")
# set(OPENCV_RELEASE_DLL_NAMES "-llibopencv_core452 -llibopencv_highgui452")
# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
#     target_link_libraries(wxWidgetsCAD "${OPENCV_DEBUG_DLL_NAMES}")
#     message("链接到opencv的相关库:${OPENCV_DEBUG_DLL_NAMES}")
# elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
#     target_link_libraries(wxWidgetsCAD "${OPENCV_RELEASE_DLL_NAMES}")
#     message("链接到opencv的相关库:${OPENCV_RELEASE_DLL_NAMES}")
# else()
#     target_link_libraries(wxWidgetsCAD "${OPENCV_RELEASE_DLL_NAMES}")
#     message("链接到opencv的相关库:${OPENCV_RELEASE_DLL_NAMES}")
# endif()

# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
#     file(GLOB OPENCV_DEBUG_DLL "${OPENCV_DLL_PATH}/libopencv_*${OPENCV_VERSION}d.dll")
#     file(COPY ${OPENCV_DEBUG_DLL} DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
#     message("拷贝opencv相关dll,${OPENCV_DEBUG_DLL_NAMES},到目录${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
#     file(GLOB OPENCV_RELEASE_DLL "${OPENCV_DLL_PATH}/libopencv_*${OPENCV_VERSION}.dll")
#     file(COPY ${OPENCV_RELEASE_DLL} DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
#     message("拷贝opencv相关dll:${OPENCV_RELEASE_DLL_NAMES},到目录${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# else()
#     file(GLOB OPENCV_RELEASE_DLL "${OPENCV_DLL_PATH}/libopencv_*${OPENCV_VERSION}.dll")
#     file(COPY ${OPENCV_RELEASE_DLL} DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
#     message("拷贝opencv相关dll:${OPENCV_RELEASE_DLL_NAMES},到目录${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# endif()
# file(GLOB OPENCV_FFMPEG_DLL "${OPENCV_DLL_PATH}/*ffmpeg${OPENCV_VERSION}*.dll")
# file(COPY ${OPENCV_FFMPEG_DLL} DESTINATION DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
# #opencv配置结束


set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)